package de.haw.shc.JSONObjects;

import android.util.Log;
import de.haw.shc.Interfaces.DeviceProperty.iWindow;
import de.haw.shc.Action.Actions;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: mizus
 * Date: 08.05.13
 * Time: 14:44
 * To change this template use File | Settings | File Templates.
 */
public class Window implements iWindow {

    private int open = 20;
    private int close = 0;
    private String speed = "SLOW";
    private String name, id, raum, viewName, viewRaumName;


    public Window(){
    }


    @Override
    public JSONObject createCloseWindowObject(){
        Map<String, JSONArray> buildMap = createMap(speed, String.valueOf(close), name);
        JSONObject jsonObj = new JSONObject(buildMap);
        Log.d("iWindow.createCLoseWindowObject", jsonObj.toString());
        return jsonObj;
    }


    @Override
    public JSONObject createOpenWindowObject(){
        Map<String, JSONArray> buildMap = createMap(speed, String.valueOf(open), name );
        JSONObject jsonObj = new JSONObject(buildMap);
        Log.d("iWindow.createOpenWindow", jsonObj.toString());
        return jsonObj;
    }

    @Override
    public JSONObject createSelfSettingsObject(int offen){
        Map<String, JSONArray> buildMap = createMap(speed, String.valueOf(offen), name);
        JSONObject jsonObject = new JSONObject(buildMap);
        Log.d("iWindow.createSelfOpenClose", jsonObject.toString());
        return jsonObject;
    }

    private static Map<String, JSONArray> createMap(String Speed, String action, String window){
        Map<String, JSONArray> resultMap = new HashMap<String, JSONArray>();
        JSONArray resultList = new JSONArray();
        resultList.put(String.valueOf(action));
        resultList.put(Speed);
        resultMap.put(window, resultList);
        return resultMap;
    }

    @Override
    public JSONObject deactivate() {
        return createCloseWindowObject();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public JSONObject activate(){
        return this.createOpenWindowObject();
    }



    @Override
    public String getName() {
        return name;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getID() {
        return id;
    }

    @Override
    public void setRaum(String aRaum) {
        raum = aRaum;
    }

    @Override
    public String getRaum() {
        return raum;
    }

    @Override
    public void setName(String aName){
        name = aName;
    }

    @Override
    public void setID(String aID){
        id = aID;
    }

    @Override
    public boolean isColorPicker() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setColorable(boolean bool) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setViewName(String name) {
        viewName = name;//To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getViewName() {
        return viewName;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setViewRaumName(String name) {
      viewRaumName = name;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getViewRaumName() {
        return viewRaumName;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isWindow() {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isBlind() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isLight() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isRadiator() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isCurtain() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getDeviceControll() {
        return Actions.WINDOWCONTROL;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String toString(){
        return "Name: " + viewName + " Room: "+ viewRaumName;
    }


}
